home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Scope / Scope Disk #077 (199x)(Scope PD)(US)[WB].zip / Scope Disk #077 (199x)(Scope PD)(US)[WB].adf / BTutor / BasicTutorial < prev    next >
Text File  |  1989-08-16  |  11KB  |  352 lines

  1.  
  2.                AmigaBASIC Tutorial #1
  3.  
  4.                      Written by
  5.                    Pierre Fortin
  6.  
  7.   --------------------------------------------------------------------------
  8. INTRODUCTION:
  9.  
  10.      The following tutorial is for the use of AmigaBASIC programmers both
  11. novice and intermidiate programmers can benfit from this tutorial.
  12. Part 1 (this tutorial) contains information which is quite useful so if
  13. possible, read this file with a program that can let you print your current
  14. screen so that you can create yourself a quick refrence card.  The following
  15. tutorial will cover the following:
  16.  
  17.         How to access libraries in AmigaBASIC
  18.         How to use CLI commands
  19.         How to interface I/O with your modem
  20.     and    How to create a console window in AmigaBASIC.
  21.  
  22.   --------------------------------------------------------------------------
  23. Accessing libraries in AmigaBASIC
  24.   --------------------------------------------------------------------------
  25.  
  26.      AmigaBASIC has a very extensive command set of 198 commands.  More than
  27. enough to accomplish many tasks.  Though limitiations do arrise.  For
  28. example, what if you wanted to read the current color pallete values?  There
  29. is no specific command to do so!  What does one do when faced with such a
  30. problem?  One uses specific commands within those 198 commands in the
  31. AmigaBASIC set to call up ROM Kernal routines.  I won't go much further
  32. into the subject of libraries for it is all documented with the AmigaBASIC
  33. manual included with your Amiga.  I mentioned libraries for many of the
  34. routines and tips in this file and hopefully others include access to
  35. libraries.  This is why you MUST have the following libraries in your
  36. current directory from when you boot up AmigaBASIC or in the LIBS:
  37. directory of your system disk.
  38.  
  39.     dos.bmap
  40.     intuition.bmap
  41.     exec.bmap
  42.  
  43.   --------------------------------------------------------------------------
  44. How to use CLI commands in AmigaBASIC
  45.   --------------------------------------------------------------------------
  46.  
  47.      The following part of this text file includes code to call CLI
  48. commands from AmigaBASIC.  CLI is a medium used by a large majority of
  49. Amiga users.  This enviroment is controlled by small programs called
  50. commands.  These commands do many tasks such as list the content of the
  51. disk, give you information about the disk, delete files, copy files,
  52. and much, much more...  To access these programs (refered as commands
  53. from here on) would greatly increase the power and complexity of your
  54. AmigaBASIC program(s).  The following list can be typed into the
  55. AmigaBASIC editor and saved as ASCII. (Saving in ASCII is explained at
  56. the end of this document.)  These files can then be merged to your program
  57. and by CALLing this subroutine, you will be able to execute CLI commands
  58. from AmigaBASIC.
  59.  
  60. Place the following at the beginning of your program:
  61.  
  62. DECLARE FUNCTION xOpen& LIBRARY
  63. DECLARE FUNCTION Execute% LIBRARY
  64. LIBRARY "dos.library"
  65.  
  66. This is the subroutine:
  67.  
  68. SUB CLI (Command$) STATIC
  69.   SHARED error.code%
  70.   work$=Command$+CHR$(0)
  71.   count%=0
  72.   
  73.   out.filename$="RAM:CLI.OUT"
  74.   out$=out.filename$+CHR$(0)
  75.   
  76.   out.handle&=xOpen&(SADD(out$),1006)
  77.   IF out.handle&=0 THEN
  78.     error.code%=1
  79.     EXIT SUB
  80.   END IF
  81.   
  82.   follow%=Execute%(SADD(work$),0,out.handle&)
  83.   IF follow%=false THEN
  84.     error.code%=2
  85.     EXIT SUB                                          
  86.   END IF
  87.  
  88.   CALL xClose(out.handle&)
  89.   text.height%=PEEKW(WINDOW(8)+58)
  90.   window.height%=PEEKW(WINDOW(7)+10)-11
  91.   lines%=INT(window.height%/text.height%)-3
  92.  
  93. OPEN out.filename$ FOR INPUT AS 1
  94.   WHILE (EOF(1)=0)
  95.     INPUT #1,reader$
  96.     count%=count%+1
  97.     IF count%>lines% THEN
  98.       count%=0
  99.       PRINT "<< Press any key to continue >>";
  100.       WHILE INKEY$="":WEND
  101.       PRINT
  102.     END IF
  103.   WEND
  104.   PRINT "## End output ##"
  105. CLOSE 1
  106.   KILL out.filename$
  107. END SUB  
  108.  
  109. The following syntax should be used to call this routine.
  110.  
  111.     CLI "{COMMAND}"
  112.  
  113.    Ex.  CLI "dir df1:"
  114.  
  115. The previous example would read the directory of DF1: and output it to
  116. a file in RAM: called CLI.OUT.  This file would then be displayed and the
  117. subroutine would return to where you called from within your program.
  118.  
  119.   --------------------------------------------------------------------------
  120. How to interface I/O with your modem
  121.   --------------------------------------------------------------------------
  122.  
  123.      Accessing your modem from AmigaBASIC is very simple.  There is
  124. no LIBRARY call's to use your modem from AmigaBASIC, the routine uses 
  125. internal commands.  You simply open the communication port at the baud
  126. rate of your choice (also depends on the highest speed of your modem.)
  127.  
  128.     OPEN "COM1:{Baud Rate},{Parity},{Data Bits},{Stop Bits} AS #1
  129.  
  130. Just replace the name in brackets with the appropriate values.  These
  131. values are explained in your AmigaBASIC manual.
  132.  
  133.      You must then place yourself in a wait state and wait for input
  134. from the modem.  This is achieved with the help of the LOC command.
  135.  
  136.     WHILE LOC(1)=0:WEND
  137.     {Rest of routine goes here}
  138.  
  139. This particular syntax wait's until a character is pending from the modem
  140. and then goes on to continue where you place your routine.  (Porperly
  141. marked in the above example.)  These are a few other commands you can
  142. use with the modem.
  143.  
  144.     modeminput$=INPUT$({Number of Characters},1) 'Modem input
  145.             INPUT$ #1,modeminput$
  146.  
  147.     PRINT #1,"This is going to the modem!!"
  148.  
  149. * NOTE: The number 1 [ONE] in the above examples is the file number and
  150. may be changed at will!
  151.  
  152.   --------------------------------------------------------------------------
  153. How to create a console window in AmigaBASIC
  154.   --------------------------------------------------------------------------
  155.  
  156.      The proper title to this final section in this tutorial would be a
  157. faster print command.  The routine is fairly complex so I will
  158. display it and then comment on it.
  159.  
  160. Place these at the beginning of your program:
  161.  
  162. DECLARE FUNCTION OpenDevice% LIBRARY
  163. DECLARE FUNCTION AllocMem& LIBRARY
  164. DECLARE FUNCTION AllocSignal% LIBRARY
  165. DECLARE FUNCTION FindTask& LIBRARY
  166. DECLARE FUNCTION DoIO& LIBRARY
  167. LIBRARY "exec.library"
  168.  
  169. C1$=CHR$(155)       ' Control Sequence Introducer
  170. C2$=CHR$(8)         ' Backspace
  171. C3$=CHR$(10)        ' Line Feed
  172. C4$=CHR$(11)        ' VTab
  173. C5$=CHR$(12)        ' Form Feed
  174. C6$=CHR$(13)        ' CR
  175. C7$=CHR$(14)        ' SHIFT IN
  176. C8$-CHR$(15)        ' SHIFT OUT
  177. C9$=CHR$(155)+"1E"  'RETURN
  178.  
  179. The subroutines:
  180.  
  181. SUB ConPrint(text$) STATIC
  182.   SHARED c.io&
  183.   IF c.io&=0 THEN :SystemOn
  184.   POKEL c.io&+36,LEN(text$)
  185.   POKEL c.io&+40,SADD(text$)
  186.   e&=DoIO&(c.io&)
  187. END SUB
  188.  
  189. SUB SystemOff STATIC
  190.   SHARED c.io&
  191.   CloseConsole c.io&
  192. END SUB
  193.  
  194. SUB SystemOn STATIC
  195.   SHARED c.io&,c.c$
  196.   OpenConsole c.io&
  197.   POKEW c.io&+28,3
  198. END SUB
  199.  
  200. SUB OpenConsole(result&) STATIC
  201.   CreatePort "basic.con",0,c.port&
  202.   IF c.port&=0 THEN ERROR 255
  203.   CreateStdIO c.port&,c.io&
  204.   POKEL c.io&+36,124
  205.   POKEL c.io&+40,WINDOW(7)
  206.   dev$="console.device"+CHR$(0)
  207.   c.error%=OpenDevice%(SADD(dev$),0,c.io&,0)
  208.   IF c.error%<>0 THEN ERROR 255
  209.   result&=c.io&
  210. END SUB
  211.  
  212. SUB CloseConsole(io&) STATIC
  213.   port&=PEEKL(io&+14)
  214.   CALL CloseDevice(io&)
  215.   RemovePort port&
  216.   RemoveStdIO io&
  217. END SUB
  218.  
  219. SUB CreateStdIO (port&,result&) STATIC
  220.   opt&=2^16
  221.   result&=AllocMem&(48,opt&)
  222.   IF result&=0 THEN ERROR 7
  223.   POKE result&+8,5
  224.   POKEL result&+14,port&
  225.   POKEW result&+18,50
  226. END SUB
  227.  
  228. SUB RemoveStdIO (io&) STATIC
  229.   IF io&<>0 THEN
  230.     CALL FreeMem(io&,48)
  231.   END IF
  232. END SUB
  233.  
  234. SUB CreatePort (port$,pri%,result&) STATIC
  235.   opt&=2^16
  236.   byte&=38+LEN(port$)
  237.   port&=AllocMem&(byte&,opt&)
  238.   IF port&=0 THEN ERROR 7
  239.   POKEW port&,byte&
  240.   port&=port&+2
  241.   sigBit%=AllocSignal%(-1)
  242.   IF sigBit%=-1 THEN
  243.     CALL FreeMem(port&,byte&)
  244.     ERROR 7
  245.   END IF
  246.   sigTask&=FindTask&(0)
  247.   
  248.   POKE port&+8,4
  249.   POKE port&+9,pri%
  250.   POKEL port&+10,port&+34
  251.   POKE port&+15,sigBit%
  252.   POKEL port&+16,sigTask&
  253.   POKEL port&+20,port&+24
  254.   POKEL port&+28,port&+20
  255.   FOR loop%=1 TO LEN(port$)
  256.     char%=ASC(MID$(port$,loop%,1))
  257.     POKE port&+33+loop%,char%
  258.   NEXT loop%
  259.   CALL AddPort(port&)
  260.   result&=port&
  261. END SUB
  262.  
  263. SUB RemovePort(port&) STATIC
  264.   byte&=PEEKW(port&-2)
  265.   sigBit%=PEEK(port&+15)
  266.   CALL RemPort(port&)
  267.   CALL FreeSignal(sigBit%)
  268.   CALL FreeMem(port&-2,byte&)
  269. END SUB
  270.  
  271. The above collection of SUBroutines will allow to print to your current
  272. window using all ANSI escape codes, and will also create a CLI type cursor
  273. and control it for you.  I will document the code for it is an extract
  274. of the Abacus book "Amiga Tricks and Tips."  (More on this at the end
  275. of this tutorial.)  You simply call the routine like this:
  276.  
  277.     ConPrint "Hello, this is printing using ConPrint!!!"
  278.  
  279. Just do the following and the routine will create a console window
  280. on it's own.  If you wish to open the console first, just type:
  281.  
  282.     SystemOn
  283.  
  284. And when you are finished and your program quits, type:
  285.  
  286.     SystemOff
  287.  
  288. SystemOff is VERY important because it clears up allocated memory and
  289. relases ports and signals allocated to create the console window.  To use
  290. ANSI, just include the control codes within the quotes in ConPrint or
  291. use the pre-defined variables which should be placed at the beginning of
  292. your program.
  293.  
  294.   --------------------------------------------------------------------------
  295. DISCLAIMER
  296.   --------------------------------------------------------------------------
  297.  
  298.      The following file uses extractions from the following book(s):
  299.  
  300.     Abacus' Amiga Tips And Tricks
  301.  
  302.      References were tooken from the following book(s):
  303.  
  304.     Advanced Amiga Basic by Compute Publications
  305.     AmigaBASIC Manual by Microsoft
  306.  
  307. I highly recommend Abacus' Amiga Tips And Tricks to ALL AmigaBASIC
  308. programmers.  It is an EXTREAMLY userfull refrence guide.  I also
  309. recommend Advanced Amiga Basic by Compute Publications, it to is
  310. a great refrence manual.  Both these publications should be on the
  311. shelf of EVERY AmigaBASIC programmer.
  312.  
  313. if you find this tutorial handy, usefull, or even profit from it's
  314. contents, please write to me:
  315.  
  316.     Pierre Fortin
  317.     8035 Jeanne D'Arc Bd.
  318.     Orleans, Ontario, Canada
  319.     K1E 1B1
  320.  
  321. I can also be reached on:
  322.  
  323.     OMX - Steve Tibbett's BBS(X)
  324.     613-731-3419
  325.  
  326.     Compuerve
  327.     ID # 73667,3525
  328.  
  329. I will only continue this series of tutorials if there is demmand for it.
  330.  
  331. I am sorry for the spelling errors, but I don't own a spell checker!!!!
  332.  
  333. I would like to thank, Patrick Lalonde for help in writting some routines
  334. and to Peter Kaminski for his help.  I am currently writting a BBS in
  335. AmigaBASIC and it is comming along quite well.  Once completed I will
  336. send copies of the demo out to those who write to me.  The BBS will support
  337. the following:
  338.  
  339.         XMODEM, YMODEM, ZMODEM w/ 32bit-CRC (I already have the
  340.                              routines!)
  341.         Complete message system
  342.         255 security level system
  343.         Voting
  344.         Configurable menus
  345.         more...
  346.  
  347. A demo version will be available to those interested in putting up the bbs.
  348. Producing tutorial's of this type is hard work, to those who find this
  349. tutorial useful, a small donation of about 5$ would be greatly appreciated.
  350. Send donations to the above address.  Those who send donations will
  351. receive a copy of my BBS (when it's finished) and all the updates.
  352.